package org.uturn.timeshift.utils.utils;


import org.uturn.timeshift.web.menus.utils.MenuModel;

import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBException;
import javax.xml.bind.Unmarshaller;

import java.io.File;
import java.io.IOException;

/**
 * Created by przemyslaw.sudak on 2/27/2015.
 */
public class XMLConverter {

    public XMLModel jaxbXMLToObject(String file) throws IOException {

        XMLModel model;
        ClassLoader classLoader = getClass().getClassLoader();

        try{
            File f = new File(classLoader.getResource(file).getFile());
            JAXBContext context = JAXBContext.newInstance(MenuModel.class);
            Unmarshaller un = context.createUnmarshaller();
            model = (MenuModel) un.unmarshal(f);
            return model;

        }catch(JAXBException e){
            e.printStackTrace();
        }
        return null;
    }


}
